﻿using System.Collections.Generic;
using Mayando.Web.Models;

namespace Mayando.Web.Infrastructure
{
    /// <summary>
    /// Defines a navigation context for photos.
    /// </summary>
    public class NavigationContext
    {
        #region Properties

        /// <summary>
        /// Gets all the photos in the navigation context.
        /// </summary>
        public IEnumerable<Photo> Photos { get; private set; }

        /// <summary>
        /// Gets the current photo in the navigation context.
        /// </summary>
        public Photo Current { get; private set; }

        /// <summary>
        /// Gets the type of navigation context.
        /// </summary>
        public NavigationContextType? Type { get; private set; }

        /// <summary>
        /// Gets the criteria for the navigation context.
        /// </summary>
        public string Criteria { get; private set; }

        /// <summary>
        /// Gets a description of the navigation context.
        /// </summary>
        public string Description { get; private set; }

        /// <summary>
        /// Gets a URL to the overview page of the navigation context.
        /// </summary>
        public string OverviewUrl { get; private set; }

        /// <summary>
        /// Gets the index of the current photo in the navigation context.
        /// </summary>
        public int CurrentIndexInNavigationContext { get; private set; }

        /// <summary>
        /// Gets the previous photo in the navigation context.
        /// </summary>
        public Photo Previous { get; private set; }

        /// <summary>
        /// Gets the next photo in the navigation context.
        /// </summary>
        public Photo Next { get; private set; }

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationContext"/> class.
        /// </summary>
        /// <param name="photos">All the photos in the navigation context.</param>
        /// <param name="current">The current photo in the navigation context.</param>
        /// <param name="type">The type of navigation context.</param>
        /// <param name="criteria">The criteria for the navigation context.</param>
        /// <param name="description">A description of the navigation context.</param>
        /// <param name="overviewUrl">A URL to the overview page of the navigation context.</param>
        public NavigationContext(IList<Photo> photos, Photo current, NavigationContextType? type, string criteria, string description, string overviewUrl)
        {
            this.Photos = photos;
            this.Current = current;
            this.Type = type;
            this.Criteria = criteria;
            this.Description = description;
            this.OverviewUrl = overviewUrl;

            this.CurrentIndexInNavigationContext = photos.IndexOf(this.Current);
            if (this.CurrentIndexInNavigationContext > 0)
            {
                this.Previous = photos[this.CurrentIndexInNavigationContext - 1];
            }
            if (this.CurrentIndexInNavigationContext < photos.Count - 1)
            {
                this.Next = photos[this.CurrentIndexInNavigationContext + 1];
            }
        }

        #endregion
    }
}